<?php
/*生成一个树形表*/
class TreetbHelper extends AppHelper
{
    var $strpre='';
    var $rownums=0;
    var $reuslt='';
    function node2row($spre='--',$treeNode,$mainfield='name',$istop=false)
    {
        $row='';
        $baseurl=Configure::read('App.baseUrl');
        if(empty($treeNode) or !is_array($treeNode))
            return null;
        $curspre=$istop?'':$this->strpre.$spre;
        $name=$curspre.$treeNode['Type'][$mainfield];
        $hided = $treeNode['Type']['hide']?'隐藏':'显示';
        if($this->rownums % 2 != 0)
                $row.="<tr class='odd'>";
        else
                $row.='<tr>';
        $row.= 
        "<td class='rowhead'>{$treeNode['Type']['id']}</td>
        <td class='leftalign'>$name</td>
        <td>{$treeNode['Type']['parent_id']}</td><td>{$treeNode['Type']['pri']}</td>
        <td>{$treeNode['Type']['tplName']}</td>
        <td>$hided</td>
        <td>
        <input type='checkbox' id='node{$treeNode['Type']['id']}' value='{$treeNode['Type']['id']}' />
        <a href='{$baseurl}admin/types/remove/{$treeNode['Type']['id']}'>删除</a>
        <a href='{$baseurl}admin/types/edit/{$treeNode['Type']['id']}'>编辑</a>
        <a href='{$baseurl}admin/types/createTypeHtml/{$treeNode['Type']['id']}'>生成</a>
        </td>
        </tr>";
        $this->result.=$row;
        $this->rownums++;
        if(!empty($treeNode['children'])){
            $oldspre=$this->strpre;
            $this->strpre=$curspre;
            foreach($treeNode['children'] as $childNode){
                $this->node2row($spre,$childNode,$mainfield);
            }
            $this->strpre=$oldspre;
        }
        return $this->result;
    }
}
?>